$(document).ready(function() {
	var title;
	var x=Array();
	var y=Array();
	var ymax,ymin;
	var option = {};

function setopt(id){
	title="";
	x=Array();
	y=Array();
	ymax,ymin;
	option = {};

	$.ajax({      
		'url': "https://wx.jiao-xw.com/api/v1/pricelist",
		'async':false,
		'type': "post",
		"data": {
			'product_id': id,
      'date_limit': 200
     },
		'success': function(res) {        
			console.log(res);
			var arr = res.data.list;
			title = res.data.list[0].pro_name;
			ymax = res.data.max_value;
			ymin = res.data.min_value;
			for(i=0;i<arr.length;i++){
					x.push(arr[i].date);
					y.push(arr[i].price);
			}
		}    
	})

	option = {
		color: ["#007aff"],
		title: {
			text: title,
          subtext: "",
          textAlign: "left",
          x: "center",
          y: "top",
          top: 10,
          textStyle: {
            color: "#007aff",
            fontWeight: "400",
            fontSize: 14,
          },
          subtextStyle: { color: "#20a162", fontWeight: "100" },
		},
		tooltilp: {
			trigger: "axis",
			triggerOn: "mousemove",
			showContent: true,
		},
		legengd: {
			data: ["user from"]
    },
        tooltip: {
          trigger: "axis",
          triggerOn: "mousemove",
          showContent: true,
        },
		xAxis: {
			name:'日期',
			data: x,
			axisTick: {
				inside: true,
			},
		},
		yAxis: {
			name:'元/吨',
			scale:false,
			axisLine: {show:true},
			axisTick: {show:true},
			position:'left',
			max : ymax,
			min : ymin,
		},
		series: [{
			name: '价格:',
			type: 'line',
			symbol: 'circle',
			data: y
    }],
		dataZoom: [{ 
			type: 'slider',
			show: true,
			startValue: 0,
			endValue: 200,
			height: '30',
			bottom: '5%',
			zoomLock: true
		}],
   };
}


	var myChart1 = echarts.init(document.getElementById('chartmain1'));
	var myChart2 = echarts.init(document.getElementById('chartmain2'));
	var myChart3 = echarts.init(document.getElementById('chartmain3'));
	setopt(20);
	myChart1.setOption(option);
	setopt(33);
	myChart2.setOption(option);
	setopt(34);
	myChart3.setOption(option);
});
